package controllers;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entities.Article;

import models.ArticleModel;

public class PrintEmailAcceptServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		String id = (String) request.getParameter("id");
		String key = (String) request.getParameter("key");
		
		ArticleModel articleModel = ArticleModel.getInstance();
		Article article = articleModel.getArticle(id);
		
		if (article != null && !article.getAuthKey().equalsIgnoreCase(key)) {
			article = null;
		}
		
		request.setAttribute("article", article);
		try {
			request.getRequestDispatcher("/print/email_accept.jsp").forward(request, response);
		} catch (ServletException e) {
			//e.printStackTrace();
		}
	}
}
